#install rabbitmq-server and enable run
rabbitmq-server-single:
  pkg.installed:
    - name: rabbitmq-server
  service.running:
    - name: rabbitmq-server
    - enable: True
    - require:
      - pkg: rabbitmq-server-single

#create new user for openstack
rabbitmq-user-openstack:
  file.managed:
    - name: /etc/script/rabbitmq-openstack.sh
    - source: salt://openstack/queen/rabbitmq/files/rabbitmq-openstack.sh
    - user: root
    - group: root
    - mode: 700
    - template: jinja
    - defaults:
      RABBITMQ_OPENSTACK_USER: {{ pillar['rabbitmq']['RABBITMQ_OPENSTACK_USER'] }}
      RABBITMQ_OPENSTACK_PASS: {{ pillar['rabbitmq']['RABBITMQ_OPENSTACK_PASS'] }}
      RABBITMQ_GUEST_PASS: {{ pillar['rabbitmq']['RABBITMQ_GUEST_PASS'] }}
  cmd.run:
    - name: bash /etc/script/rabbitmq-openstack.sh && echo {{ pillar['rabbitmq']['RABBITMQ_OPENSTACK_PASS'] }} >/etc/lock/rabbitmq-user-openstack.lock
    - require:
      - service: rabbitmq-server-single
      - file: rabbitmq-user-openstack
    - unless: test -f /etc/lock/rabbitmq-user-openstack.lock && test `cat /etc/lock/rabbitmq-user-openstack.lock` = {{ pillar['rabbitmq']['RABBITMQ_OPENSTACK_PASS'] }}
